package com.qf.jie.controller;

import com.qf.jie.controller.servlet.BaseServlet;
import com.qf.jie.entity.po.User;
import com.qf.jie.entity.vo.RespBean;
import com.qf.jie.service.CartService;
import com.qf.jie.service.impl.CartServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/CartController")
public class CartController extends BaseServlet {
    CartService cartService = new CartServiceImpl();

    // 1.添加购物车
    protected RespBean addCart(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String commodity_id = req.getParameter("commodity_id");
        System.out.println("添加购物车" + commodity_id);
        return cartService.addCart(req, commodity_id);
    }
    // 2.删除购物车
    protected RespBean deletetById(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        return cartService.deletetById(id);
    }
    //3.获取购物车
    protected RespBean getListByUser_id(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //String user_id = req.getParameter("user_id");
        //临时改动
        User user = (User)req.getSession().getAttribute("user");
        return cartService.getListByUser_id(user.getId() + "");
    }

}
